<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<link href="${pageContext.request.contextPath}/statics/css/common.css" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/statics/css/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<c:if test="${auctionList == null}">
  <script type="text/javascript">
    location.href = "${pageContext.request.contextPath}/SrecordList";
  </script>
</c:if>
<form method="post" action="${pageContext.request.contextPath}/SrecordList">
  <input type="hidden" name="pageIndex" value="1"/>
<div class="wrap">
<!-- main begin-->
  <div class="sale">
    <h1 class="lf">在线拍卖系统</h1>
  	<c:if test="${not empty auctionUserSession}">
    	<div class="logout right"><a href="${pageContext.request.contextPath}/Sexit" title="注销">注销</a></div>
    </c:if>
    <c:if test="${empty auctionUserSession}">
    	<div class="logout right"><a href="${pageContext.request.contextPath}/login.jsp" title="登录">登录</a></div>
    </c:if>
  </div>
  <div class="forms">
    <label for="name">名称</label>
    <input name="auctionName" type="text" class="nwinput" id="name" value="${auctionName}"/>
    <label for="names">描述</label>
    <input name="auctionDesc" type="text" id="names" class="nwinput" value="${auctionDesc}"/>
    <label for="time">开始时间</label>
    <input name="auctionStartTime" type="text" id="time" class="nwinput" value="${auctionStartTime}"/>
    <label for="end-time">结束时间</label>
    <input name="auctionEndTime" type="text" id="end-time" class="nwinput" value="${auctionEndTime}"/>
    <label for="price">起拍价</label>
    <input name="auctionStartPrice" type="text" id="price" class="nwinput" value="${auctionStartPrice}"/>
    <input type="submit"  value="查询" class=""/>
    <c:if test="${auctionUserSession.userIsAdmin == 1}">
    	<input type="button" onclick="location='StoaddAuction'" value="发布" class=""/>
    </c:if>
    <br/>
    <c:if test="${auctionUserSession.userIsAdmin == 0}">
      &nbsp;&nbsp;&nbsp;&nbsp;
      <a href="${pageContext.request.contextPath}/SauctionResult"><b>查看竞拍结果</b></a>
      </c:if>
  </div>
  <div class="items">
      <ul class="rows even strong">
        <li>名称</li>
        <li class="list-wd">描述</li>
        <li>开始时间</li>
        <li>结束时间</li>
        <li>起拍价</li>
        <li class="borderno">操作</li>
      </ul>
      <c:forEach items="${auctionList}" var="auction" varStatus="status">
          <ul class="rows" <c:if test="${status.index % 2 == 1}">style="background: #EBF6FA" </c:if>>
            <li>${auction.auctionName }</li>
            <li class="list-wd">${auction.auctionDesc }</li>
            <li><fmt:formatDate value="${auction.auctionStartTime }" pattern="yyyy-MM-dd HH:mm:ss"/> </li>
            <li><fmt:formatDate value="${auction.auctionEndTime }" pattern="yyyy-MM-dd HH:mm:ss"/></li>
            <li>${auction.auctionStartPrice }</li>
            <li class="borderno red">
                <c:if test="${auctionUserSession.userIsAdmin == 1}">
                  <a name="update" href="${pageContext.request.contextPath}/SauctionInfo?id=${auction.auctionId }">修改</a>
                  &nbsp;&nbsp;|&nbsp;&nbsp;
                  <a name="del" auctionEndTime="${auction.auctionEndTime}" auctionStartTime="${auction.auctionStartTime}" auctionId="${auction.auctionId }" auctionName="${auction.auctionName }">删除</a>
                </c:if>
                <c:if test="${auctionUserSession.userIsAdmin == 0}">
                    <a href="${pageContext.request.contextPath}/SauctionDetail?id=${auction.auctionId}" name="jingpai" auctionEndTime="${auction.auctionEndTime}" auctionStartTime="${auction.auctionStartTime}">竞拍</a>
              </c:if>
            </li>
          </ul>

      </c:forEach>
      <div class="page">
        <div id="datatable-responsive_info"
             role="status" aria-live="polite">共${pages.totalCount }条记录
          ${pages.currentPageNo }/${pages.totalPageCount }页
        </div>
        <a href="javascript:page_nav(document.forms[0],1)">首页</a>
        <c:if test="${pages.currentPageNo > 1}">
          <a href="javascript:page_nav(document.forms[0],${pages.currentPageNo-1})">上一页</a>
        </c:if>
        <c:if test="${pages.currentPageNo < pages.totalPageCount }">
        	<a href="javascript:page_nav(document.forms[0],${pages.currentPageNo+1 })">下一页</a>
        </c:if>
        <a href="javascript:page_nav(document.forms[0],${pages.totalPageCount })" >尾页</a>
      </div>
  </div>
<!-- main end-->
</div>
</form>
<script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.8.3.js"></script>
<script type="text/javascript">
  function page_nav(frm,num){
    frm.pageIndex.value = num;
    frm.submit();
  }

  // $("[name='jingpai']").on("click",function(){
  //   alert(obj.attr("auctionStartTime"));
  //   var obj = $(this);
  //   if ((Date.parse(obj.attr("auctionEndTime")) - new Date() <= 0 || Date.parse(obj.attr("auctionStartTime")) - new Date() >= 0)){
  //     return false;
  //   }else {
  //     return true;
  //   }
  // }

  $("[name='del']").on("click",function(){
    var obj = $(this);
    if (Date.parse(obj.attr("auctionEndTime")) - new Date() <= 0 || Date.parse(obj.attr("auctionStartTime")) - new Date() >= 0){
      if(confirm("你确定要删除拍卖品【"+obj.attr("auctionName")+"】吗？")){
        $.ajax({
          type:"GET",
          url:"${pageContext.request.contextPath}/Sdel",
          data:{id:obj.attr("auctionId")},
          dataType:"text",
          success:function(data){
            if(data == "true"){//删除成功：移除删除行
              alert("删除成功");
              obj.parents("tr").remove();
              location.href = "javascript:page_nav(document.forms[0],1)"
            }else if(data == "false"){//删除失败
              alert("对不起，删除拍卖品【"+obj.attr("auctionName")+"】失败");
            }
          },
          error:function(data){
            alert("对不起，删除失败");
          }
        });
      }
    }else {
      alert("拍卖品【"+obj.attr("auctionName")+"】正在拍卖中，无法删除");
      return false;
    }
  });

$(function() {

  $("form").submit(function () {  //表单提交时间
    var end = $("#end-time").val();
    var trim = $("#time").val();
    var tm = /^\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}$/;
    var tm2 = /^\d{4}$/;
    if(trim != ''){
      if (tm.test(trim) ||  tm2.test(trim)) {

      }else{
        alert("开始日期条件格式不正确!");
        return false;
      }
    }
    if(end != ''){
      if (tm.test(end)|| tm2.test(end)) {

      }else{
        alert("结束日期条件格式不正确!");
        return false;
      }
    }
    return true;
  });
});


</script>
</body>
</html>
